unit UModule_Ruang;

interface

uses
  Dialogs,
  Controls,
  SysUtils,
  Classes,
  InvokeRegistry,
  Rio,
  SOAPHTTPClient,
  ActnList;

type
  TModule_Ruang = class(TDataModule)
    HTTPRIO1: THTTPRIO;
    ActionList1: TActionList;
    PFile_Simpan: TAction;
    PFile_Edit: TAction;
    PFile_Hapus: TAction;
    PFile_Refresh: TAction;
    PMenu_Data: TAction;
    PMenu_New: TAction;
    procedure PFile_SimpanExecute(Sender: TObject);
    procedure PFile_EditExecute(Sender: TObject);
    procedure PFile_HapusExecute(Sender: TObject);
    procedure PFile_RefreshExecute(Sender: TObject);
    procedure PMenu_DataExecute(Sender: TObject);
    procedure PMenu_NewExecute(Sender: TObject);
    procedure DataModuleCreate(Sender: TObject);
    procedure HTTPRIO1AfterExecute(const MethodName: string; SOAPResponse: TStream);
  private
    FRuangStatus_Simpan: string;
    FRuangStatus_ID:     word;
    procedure Assign_LoginInfo;
  public
    procedure Assign_Action;
  end;

var
  Module_Ruang: TModule_Ruang;

implementation

uses
  soap_sis_ruang,
  UUser,
  UMainApplication;
{$R *.dfm}

procedure TModule_Ruang.Assign_Action;
begin
try
  with Form_Main do
    begin
    TMB0105010501020101.Action := PFile_Simpan;
    TMB0105010501010201.Action := PFile_Edit;
    TMB0105010501010202.Action := PFile_Hapus;
    TMB0105010501010203.Action := PFile_Refresh;
    with CB010501 do
      begin
      with Categories[4] do
        begin
        Items[0].Action := PMenu_Data;
        Items[1].Action := PMenu_New;
        end;
      end;
    end;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Ruang.Assign_LoginInfo;
begin
try
  with Form_Main do
    begin
    GServer_Host     := IN010301.Text;
    GServer_Database := IN010302.Text;
    GServer_UserName := IN010303.Text;
    GServer_Password := IN010304.Text;
    GUserName        := LE01010101.Text;
    GUserPassword    := LE01010102.Text;
    end;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Ruang.DataModuleCreate(Sender: TObject);
begin
try
  FRuangStatus_Simpan := 'NEW';
  FRuangStatus_ID     := 0;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Ruang.HTTPRIO1AfterExecute(const MethodName: string; SOAPResponse: TStream);
var
  LocalStrings: TStringList;
begin
try
  LocalStrings          := TStringList.Create;
  SOAPResponse.Position := 0;
  LocalStrings.LoadFromStream(SOAPResponse);
  // ShowMessage(LocalStrings.Text);
  FreeAndNil(LocalStrings);
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Ruang.PFile_EditExecute(Sender: TObject);
begin
try
  with Form_Main, Grid01050105010101 do
    begin
    FRuangStatus_Simpan   := 'EDIT';
    FRuangStatus_ID       := Cell[1, SelectedRow].AsInteger;
    IN01050105010201.Text := Cell[2, SelectedRow].AsString;
    IN01050105010202.Text := Cell[3, SelectedRow].AsString;
    IN01050105010203.Text := Cell[4, SelectedRow].AsString;
    IN01050105010204.Text := Cell[5, SelectedRow].AsString;
    IN01050105010205.Text := Cell[6, SelectedRow].AsString;
    IN01050105010206.Text := Cell[7, SelectedRow].AsString;
    with IN01050105010201 do
      begin
      Show;
      SetFocus;
      end;
    end;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Ruang.PFile_HapusExecute(Sender: TObject);
var
  InfoServer: TInfoServer;
begin
try
  case MessageDlg('Apakah anda yakin akan menghapus data mata pelajaran ini?', mtConfirmation, [mbYes, mbCancel], 0) of
    mrYes:
      begin
      Assign_LoginInfo;
      InfoServer                 := TInfoServer.Create;
      InfoServer.Server_Host     := GServer_Host;
      InfoServer.Server_Database := GServer_Database;
      InfoServer.Server_Username := GServer_UserName;
      InfoServer.Server_Password := GServer_Password;
      with Form_Main, HTTPRIO1 as SERVICE_RUANGPortType do
        begin
        RUANG_HAPUS(InfoServer, Grid01050105010101.Cell[1, Grid01050105010101.SelectedRow].AsInteger);
        with Grid01050105010101 do
          begin
          BeginUpdate;
          DeleteRow(SelectedRow);
          EndUpdate;
          end;
        end;
      end;
    mrCancel:
      begin
      // Ignore this process
      end;
  end;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Ruang.PFile_RefreshExecute(Sender: TObject);
var
  InfoServer:      TInfoServer;
  InfoDaftarRuang: TInfoDaftarRuang;
  LocalIndex:      word;
  LocalCount:      word;
begin
try
  InfoServer := TInfoServer.Create;
  Assign_LoginInfo;
  with Form_Main, HTTPRIO1 as SERVICE_RUANGPortType do
    begin
    InfoServer.Server_Host     := GServer_Host;
    InfoServer.Server_Database := GServer_Database;
    InfoServer.Server_Username := GServer_UserName;
    InfoServer.Server_Password := GServer_Password;
    InfoDaftarRuang            := RUANG_DATA_SEMUA(InfoServer, 'ASC');
    LocalCount                 := high(InfoDaftarRuang) + 1;
    L0105010501010101.Caption  := 'Jumlah Ruang: ' + IntToStr(LocalCount);
    if LocalCount > 0 then
      begin
      with Grid01050105010101 do
        begin
        BeginUpdate;
        ClearRows;
        AddRow(LocalCount);
        for LocalIndex := 0 to LocalCount - 1 do
          begin
          Grid01050105010101.Cell[1, LocalIndex].AsInteger := InfoDaftarRuang[LocalIndex].ID;
          Grid01050105010101.Cell[2, LocalIndex].AsString  := InfoDaftarRuang[LocalIndex].RUANG_KODE;
          Grid01050105010101.Cell[3, LocalIndex].AsString  := InfoDaftarRuang[LocalIndex].RUANG_NAMA;
          Grid01050105010101.Cell[4, LocalIndex].AsString  := InfoDaftarRuang[LocalIndex].RUANG_JENIS;
          Grid01050105010101.Cell[5, LocalIndex].AsInteger := InfoDaftarRuang[LocalIndex].RUANG_KAPASITAS;
          Grid01050105010101.Cell[6, LocalIndex].AsString  := InfoDaftarRuang[LocalIndex].RUANG_GEDUNG;
          Grid01050105010101.Cell[7, LocalIndex].AsString  := InfoDaftarRuang[LocalIndex].RUANG_KETERANGAN;
          end;
        EndUpdate;
        end;
      end;
    end;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Ruang.PFile_SimpanExecute(Sender: TObject);
var
  InfoServer: TInfoServer;
  InfoRuang:  TInfoRuang;
begin
try
  Assign_LoginInfo;
  InfoServer                 := TInfoServer.Create;
  InfoRuang                  := TInfoRuang.Create;
  InfoServer.Server_Host     := GServer_Host;
  InfoServer.Server_Database := GServer_Database;
  InfoServer.Server_Username := GServer_UserName;
  InfoServer.Server_Password := GServer_Password;
  with Form_Main, HTTPRIO1 as SERVICE_RUANGPortType do
    begin
    InfoRuang.ID               := FRuangStatus_ID;
    InfoRuang.RUANG_KODE       := IN01050105010201.Text;
    InfoRuang.RUANG_NAMA       := IN01050105010202.Text;
    InfoRuang.RUANG_JENIS      := IN01050105010203.Text;
    InfoRuang.RUANG_KAPASITAS  := StrToInt(IN01050105010204.Text);
    InfoRuang.RUANG_GEDUNG     := IN01050105010205.Text;
    InfoRuang.RUANG_KETERANGAN := IN01050105010206.Text;
    RUANG_SIMPAN(InfoServer, InfoRuang, FRuangStatus_Simpan);
    with Grid01050105010101 do
      begin
      Show;
      PFile_Refresh.Execute;
      end;
    end;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Ruang.PMenu_DataExecute(Sender: TObject);
begin
try
  with Form_Main, TAB010501050101 do
    begin
    Show;
    end;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

procedure TModule_Ruang.PMenu_NewExecute(Sender: TObject);
begin
try
  with Form_Main, IN01050105010201 do
    begin
    IN01050105010201.Clear;
    IN01050105010202.Clear;
    IN01050105010203.Clear;
    IN01050105010204.Clear;
    IN01050105010205.Text := '0';
    IN01050105010206.Clear;
    FRuangStatus_Simpan := 'NEW';
    Show;
    SetFocus;
    end;
except
  on E: Exception do
    begin
    ShowMessage(E.Message);
    end;
end;
end;

end.
